package com.github.zuihou.database.mybatis.common;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.zuihou.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.lang.reflect.Field;


/**
 * <p>
 * 实体注释中生成的类型枚举
 * 角色
 * </p>
 *
 * @author zuihou
 * @date 2019-07-21
 */
@Getter
@AllArgsConstructor
@ApiModel(value = "AreaLevel", description = "行政区域-枚举")
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum  AreaLevel  implements BaseEnum {

    PROVINCE (1, "省份直辖市"),
    CITY(2, "地市"),
    DISTRICT(3, "区县");

    @ApiModelProperty(value = "描述")
    private int val;

    private String desc;


    public static AreaLevel match(String val, AreaLevel def) {
        for (AreaLevel enm : AreaLevel.values()) {
            if (enm.name().equalsIgnoreCase(val)) {
                return enm;
            }
        }
        return def;
    }

    public static AreaLevel match(Integer val, AreaLevel def) {
        if (val == null) {
            return def;
        }
        for (AreaLevel enm : AreaLevel.values()) {
            if (val.equals(enm.getVal())) {
                return enm;
            }
        }
        return def;
    }


    public static AreaLevel get(String val) {
        return match(val, null);
    }

    public static AreaLevel get(Integer val) {
        return match(val, null);
    }

    public boolean eq(String val) {
        return this.name().equalsIgnoreCase(val);
    }

    public boolean eq(AreaLevel val) {
        if (val == null) {
            return false;
        }
        return eq(val.name());
    }


    @Override
    @ApiModelProperty(value = "编码", allowableValues = "1,2,3", example = "1")
    public String getCode() {
        return this.name();
    }

}
